package api

import (
	"github.com/labstack/echo/v4"
	"github.com/spf13/cast"
	"longmen/server/pkg/common/api_models"
	"longmen/server/pkg/common/helper/const"
	string2 "longmen/server/pkg/common/helper/string"
	"longmen/server/pkg/common/helper/util"
)

// @Summary 获取活动列表
// @Description 获取活动列表
// @Accept  json
// @Produce  json
// @Tags Activity
// @Param   sendBody body api_models.GetActivityProfileListReq true "body"
// @Success 200 {object} api_models.GetActivityProfileListResp "result"
// @Router /api/activity/getActivityProfileList [POST]
func (base *Controller) GetActivityProfileList(c echo.Context) error {
	r := &api_models.GetActivityProfileListReq{}
	if err := util.Json2Struct(c.Get("body").(string), r); err != nil {
		return util.BadParam(c, err)
	}
	if err := _const.Validate.Struct(r); err != nil {
		return util.BadParam(c, err)
	}
	resp, err := base.Service.GetActivityProfileList(string2.GetDefaultNum(r.Page, 1), string2.GetDefaultNum(r.Size, 10))
	if err != nil {
		return util.BuildFail(c, 1, "", err)
	}
	return util.BuildSuccess(c, resp, "")
}

// @Summary 根据ID获取活动详情
// @Description 根据ID获取活动详情
// @Accept  json
// @Produce  json
// @Tags Activity
// @Param   sendBody body api_models.GetActivityByIdReq true "body"
// @Success 200 {object} api_models.GetActivityByIdResp "result"
// @Router /api/activity/getActivityById [POST]
func (base *Controller) GetActivityById(c echo.Context) error {
	r := &api_models.GetActivityByIdReq{}
	if err := util.Json2Struct(c.Get("body").(string), r); err != nil {
		return util.BadParam(c, err)
	}
	if err := _const.Validate.Struct(r); err != nil {
		return util.BadParam(c, err)
	}
	resp, err := base.Service.GetActivityById(r.Id, cast.ToInt(c.Get("uid")))
	if err != nil {
		return util.BuildFail(c, 1, err.Error(), err)
	}
	return util.BuildSuccess(c, resp, "")
}

// @Summary 用户获取活动领取记录（兼容老接口，弃用）
// @Description 用户获取活动领取记录
// @Accept  json
// @Produce  json
// @Tags Activity
// @Success 200 {object} models_main.InviteRecord "result"
// @Router /api/activity/getActivityRecord [POST]
func (base *Controller) GetActivityRecord(c echo.Context) error {
	//resp, err := base.Service.GetActivityRecord(cast.ToInt(c.Get("uid")))
	//if err != nil {
	//	return common.BuildFail(c, 1, err.Error(), err)
	//}
	return util.BuildSuccess(c, nil, "")
}

// @Description 用户获取活动领取记录
// @Accept  json
// @Produce  json
// @Tags Activity
// @Success 200 {object} api_models.ActivityRecordRewordResp "result"
// @Router /api/activity/getActivityRecordNew [POST]
func (base *Controller) GetActivityRecordNew(c echo.Context) error {
	resp, err := base.Service.GetActivityRecord(cast.ToInt(c.Get("uid")))
	if err != nil {
		return util.BuildFail(c, 1, err.Error(), err)
	}
	return util.BuildSuccess(c, resp, "")
}
